using System.ComponentModel.DataAnnotations;

namespace Lzfy_His_Service.Models
{
    /// <summary>
    /// 登录失败记录模型
    /// </summary>
    public class LoginFailureLog
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required]
        [StringLength(128)]
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// 失败时间
        /// </summary>
        public DateTime FailureTime { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        [StringLength(50)]
        public string? IpAddress { get; set; }

        /// <summary>
        /// 用户代理
        /// </summary>
        [StringLength(1000)]
        public string? UserAgent { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
    }

    /// <summary>
    /// 用户锁定状态模型
    /// </summary>
    public class UserLockStatus
    {
        /// <summary>
        /// 主键ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required]
        [StringLength(128)]
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// 是否锁定(0:未锁定,1:已锁定)
        /// </summary>
        public bool IsLocked { get; set; }

        /// <summary>
        /// 锁定时间
        /// </summary>
        public DateTime? LockTime { get; set; }

        /// <summary>
        /// 解锁时间
        /// </summary>
        public DateTime? UnlockTime { get; set; }

        /// <summary>
        /// 失败次数
        /// </summary>
        public int FailureCount { get; set; }

        /// <summary>
        /// 最后失败时间
        /// </summary>
        public DateTime? LastFailureTime { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }
    }

    /// <summary>
    /// 登录失败限制配置
    /// </summary>
    public class LoginFailureLimitConfig
    {
        /// <summary>
        /// 最大失败次数（默认5次）
        /// </summary>
        public int MaxFailureCount { get; set; } = 5;

        /// <summary>
        /// 锁定时间（分钟，默认10分钟）
        /// </summary>
        public int LockDurationMinutes { get; set; } = 10;

        /// <summary>
        /// 失败记录重置时间窗口（分钟，默认30分钟）
        /// </summary>
        public int FailureResetWindowMinutes { get; set; } = 30;
    }

    /// <summary>
    /// 登录失败检查结果
    /// </summary>
    public class LoginFailureCheckResult
    {
        /// <summary>
        /// 是否被锁定
        /// </summary>
        public bool IsLocked { get; set; }

        /// <summary>
        /// 当前失败次数
        /// </summary>
        public int FailureCount { get; set; }

        /// <summary>
        /// 剩余尝试次数
        /// </summary>
        public int RemainingAttempts { get; set; }

        /// <summary>
        /// 锁定剩余时间（分钟）
        /// </summary>
        public int? LockRemainingMinutes { get; set; }

        /// <summary>
        /// 锁定到期时间
        /// </summary>
        public DateTime? LockExpiryTime { get; set; }

        /// <summary>
        /// 提示消息
        /// </summary>
        public string Message { get; set; } = string.Empty;
    }

    /// <summary>
    /// 登录失败记录请求
    /// </summary>
    public class RecordLoginFailureRequest
    {
        /// <summary>
        /// 用户名
        /// </summary>
        [Required]
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// IP地址
        /// </summary>
        public string? IpAddress { get; set; }

        /// <summary>
        /// 用户代理
        /// </summary>
        public string? UserAgent { get; set; }
    }
}